Public Class frmSearchFilter
    Dim ds As DataSet

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim oQuery As New Query
        ds = oQuery.GetQuery

        tvFields.Nodes.Clear()
        Dim rtn As TreeNode = New TreeNode("Select Fields")
        tvFields.Nodes.Add(rtn)
        Dim tb As DataTable = ds.Tables(0)
        'For Each tb As DataTable In ds.Tables

        Dim tn As TreeNode = New TreeNode(tb.TableName)
        tn.Tag = tb.TableName
        rtn.Nodes.Add(tn)

        For Each dc As DataColumn In tb.Columns
            If ds.Relations.Count = 0 Then
                tn.Nodes.Add(tb.TableName & "," & dc.ColumnName, dc.ColumnName)
            Else
                For Each rl As DataRelation In ds.Relations
                    If rl.ChildColumns(0).ColumnName = dc.ColumnName Then

                        Dim ctn As TreeNode = tn.Nodes.Add(dc.ColumnName, rl.RelationName)

                        For Each childdc As DataColumn In rl.ChildTable.Columns
                            If rl.ChildColumns(0).ColumnName <> childdc.ColumnName Then
                                ctn.Nodes.Add(childdc.Table.TableName & "," & childdc.ColumnName, childdc.ColumnName)
                            End If
                        Next

                    Else
                        tn.Nodes.Add(tb.TableName & "," & dc.ColumnName, dc.ColumnName)
                    End If

                Next
            End If
        Next
        'Next
        rtn.ExpandAll()
    End Sub

    Private Sub tvFields_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tvFields.DoubleClick
        If tvFields.SelectedNode.Nodes.Count = 0 Then
            MsgBox(tvFields.SelectedNode.Text)
        End If
        '        Dim fDS As DataSet = 

    End Sub

    Private Sub tvFields_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFields.AfterSelect

    End Sub
End Class